# @File :trainTickets.py
import time
import unittest

from configparser import ConfigParser
from Pages.PlanePage import PlanePage
from Pages.trainTicketPage import trainTicketPage
from Pages.tripPage import tripPage
from Pages.OBTTrainDetailPage import OBTTrainDetailPage
from Pages.OrderListPage import OrderListPage
from Public import Gl
from Public.Login import Login


class trainTicket(unittest.TestCase):
    def setUp(self):
        parse = ConfigParser()
        #win需使用配置文件绝对路径
        parse.read('E:\DTSL\DTSL\Public\configurations.ini')
        self.driver = Gl.BrowserEngine(self).open_browser(self)
        self.L = Login()
        self.urlOBT = parse.get('OBT','url')
        self.useridOBT = parse.get('OBT','userid')
        self.passwordOBT = parse.get('OBT','password')
        self.urlAdmin = parse.get('admin','url')
        self.useridAdmin = parse.get('admin','userid')
        self.passwordAdmin = parse.get('admin','password')


    def tearDown(self):
        self.driver.quit()

    def test_0trainTicket(self):
        PP = PlanePage()
        TT = trainTicketPage()
        self.L.LoginOBT(self.urlOBT,  self.useridOBT, self.passwordOBT)
        time.sleep(2)
        PP.closeNotice()
     #   PP.click_Close()
        TT.click_TrainTicketIcon()
        TT.selectGoDateForTrain(-2) #首页传-2，改期传0
        TT.select_TrainGoDate()
        TT.select_TrainFromCity()
        TT.select_TrainToCity()
        time.sleep(4)
     #   PP.select_GoDate(0, -1)
        #火车票是第4个
        PP.click_searchBtn(3)
        PP.closeNotice()
        TT.selectTicket(0) # 控制第几行火车票
        TT.click_youxuan()
        # 提交操作
        TT.click_submitTrainTicket()
        time.sleep(8)
        TP = tripPage()
        TP.submitTrip()
        TP.goDTDetail()
        OBTTrainDetail = OBTTrainDetailPage()
        global trainOrderNo
        trainOrderNo = OBTTrainDetail.getOrderNo()
        print(trainOrderNo)
        #全部改签传0
        OBTTrainDetail.applyChange(0)
        TT.select_TrainChangeDate()
        TT.click_SearchTrainButton()
        TT.selectTicket(0)
        TT.waitToConfirmChange()
        OBTTrainDetail.doRefund()

    '''def test_1trainTicket(self):
        PP = PlanePage()
        TT = trainTicketPage()
        self.L.LoginOBT(self.urlOBT,  self.useridOBT, self.passwordOBT)
        time.sleep(2)
        PP.closeNotice()
        PP.goOrderList()
        OL = OrderListPage()
        OL.selectOrder("DT221214310108474")
        OBTTrainDetail = OBTTrainDetailPage()
        global trainOrderNo1
        trainOrderNo1 = OBTTrainDetail.getOrderNo()
        print(trainOrderNo1)'''


if __name__ == '__main__':
    unittest.main()

